package com.huluobo.jetpackkotlindemo2006a.databinding

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.huluobo.jetpackkotlindemo2006a.viewbinding.BaseActivity

/**
 * Created by lc on 2023/2/14.
 */
class UserActivity : AppCompatActivity() {
    //    override fun getViewBinding(): ActivityUserBinding = ActivityUserBinding.inflate(layoutInflater)
    lateinit var mViewBinding: ActivityUserBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mViewBinding = ActivityUserBinding.inflate(layoutInflater)
        setContentView(mViewBinding.root)
        val user = User1Java()
        mViewBinding.user = user
        mViewBinding.userConfirm.setOnClickListener {
//            val user = getUser()
//            mViewBinding.tvUserName.text = user.username
//            mViewBinding.tvUserId.text = user.userId
            //通过双向绑定实现在activity中传递user对象给xml布局
//            mViewBinding.user = user
        }
//        mViewBinding.user = getUser()
//        mViewBinding.clickHandler = ClickHandler()
    }

    private fun getUser(): User {
        Log.i("TagA", "getUser")
        return User(
            getUserName(),
            getUserId(),
            "https://pic3.zhimg.com/v2-20ec1b6c885a660ff3c68238fce5d55b_r.jpg?source=1940ef5c￼"
        )
    }

    private fun getUserId(): String? {
        return mViewBinding.edUserId.text?.toString()
    }

    private fun getUserName(): String? {
        return mViewBinding.edUserName.text?.toString()
    }
}